package com.kcwl.carrier.infrastructure.repository.persostence;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.kcwl.carrier.domain.entity.CarrierConfig;
import com.kcwl.carrier.domain.repository.ICarrierConfigRepository;
import com.kcwl.carrier.infrastructure.repository.mapper.CarrierConfigMapper;
import com.kcwl.carrier.infrastructure.repository.po.CarrierConfigPO;
import com.kcwl.ddd.domain.repository.BaseRepositoryImpl;
import com.kcwl.ddd.interfaces.query.PageQuery;
import com.kcwl.framework.utils.KcBeanConverter;
import org.springframework.stereotype.Component;

import javax.annotation.Resource;
import java.util.Date;

/**
 * @author 刘旭超
 * @date 2022年12月05日 14:52
 * @Description
 */
@Component
public class CarrierConfigRepositoryImpl extends BaseRepositoryImpl<CarrierConfigMapper, CarrierConfigPO> implements ICarrierConfigRepository {

    @Resource
    private CarrierConfigMapper carrierConfigMapper;
    @Override
    public IPage<CarrierConfigPO> queryCarrierConfigPageList(PageQuery query) {
        IPage<CarrierConfigPO> page = new Page<>();
        page.setCurrent(query.getCurPagerNo());
        page.setSize(query.getPageSize());
        return carrierConfigMapper.selectPage(page, new QueryWrapper<>());
    }

    @Override
    public int updateCarrierConfig(CarrierConfig carrierConfig) {
        CarrierConfigPO update = KcBeanConverter.toBean(carrierConfig, CarrierConfigPO.class);
        update.setUpdateTime(new Date());
        return carrierConfigMapper.updateById(update);
    }

    @Override
    public CarrierConfigPO queryCarrierConfig(Long id) {
        return carrierConfigMapper.selectById(id);
    }

    @Override
    public Class<CarrierConfigPO> getPoClass() {
        return CarrierConfigPO.class;
    }
}
